<?php

/**
 * Created by PhpStorm.
 * User: zjc348
 * Date: 2020/7/20
 * Time: 19:09
 */


namespace app\common\behavior;
use think\Response;

class CronRun
{
    public function run(&$dispatch)
    {
        $origin=$_SERVER['HTTP_ORIGIN']??'';
        $arr=[
            'http://nfvue.asira.cn',
        ];
        $pass_origin='http://nfvue.asira.cn';
        if(in_array($origin,$arr)){
            $pass_origin=$origin;
        }

        $headers = [
            header('Access-Control-Allow-Origin: '.$pass_origin),
        header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With'),
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE'),
        header('Access-Control-Allow-Credentials:true'),
        ];
        if ($dispatch instanceof Response) {
            $dispatch->header($headers);
        } else if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
            $dispatch['type'] = 'response';
            $response = new Response('', 200, $headers);
            $dispatch['response'] = $response;
        }
    }
}